<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .wrap{
            width: 400px;
            height: 600px;
            margin: 0 auto;
            border: 1px solid red;
            padding: 20px 50px 0;
            box-sizing: border-box;
            text-align: center;
        }
        img{
            width: 300px;
            height: 400px;
            margin-bottom: 10px;
        }
        .box{
            margin: 10px auto;
            display: flex;
            justify-content: space-around;
            align-items: center;
            width: 150px;
        }
        .box input{
            width: 60px;
            height: 20px;
            outline: none;
            box-sizing: border-box;
            border: 1px solid #000;
            border-left: none;
            border-right: none;
        }
        .box div{
            display: flex;

        }
        .box div span{
            display: block;
            width: 20px;
            height: 20px;
            border: 1px solid #000;
            box-sizing: border-box;
            text-align: center;
            line-height: 20px;
        }
    </style>
</head>
<body>
    <div class="wrap">
        <img src="./练习/2.jpg" alt="">
        <p>口红</p>
        <p>￥ <span id="price">1.2</span></p>
        <div class="box">
            <span>数量：</span>
            <div>
                <span id="jian">-</span>
                <input type="text" value="0" id="num">
                <span id="jia">+</span>
            </div>
        </div>
        <p>总价：￥<span id="total"></span></p>
    </div>
    <script>
        var price = document.getElementById('price')
            var jian = document.getElementById('jian')
            var jia = document.getElementById('jia')
            var num = document.getElementById('num')
            var total = document.getElementById('total')
            
                jian.onclick = function(){
                    --num.value
                    total.innerHTML =(price.innerHTML  * num.value).toFixed(2)
                }

                jia.onclick = function(){
                    ++num.value
                    total.innerHTML =(price.innerHTML  * num.value).toFixed(2)
                }

                num.oninput = function () {
                    total.innerHTML =(price.innerHTML  * num.value).toFixed(2)
                }
            
      
    </script>
</body>
</html>